import { Component, Input, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { TenantDto } from '../proxy';

@Component({
  selector: 'app-ref-tenant-detail',
  templateUrl: './ref-tenant-detail.component.html',
})
export class RefTenantDetailComponent implements OnInit {
  validateForm: FormGroup;
  @Input() model: TenantDto;
  constructor(public fb: FormBuilder, public modalRef: NzModalRef) {}

  ngOnInit(): void {
    this.validateForm = this.fb.group({
      name: [this.model?.name, [Validators.required]],
    });
  }

  cancelForm() {
    this.modalRef.close(null);
  }

  submitForm() {
    if (!this.validateForm.valid) return;

    this.modalRef.close({
      ...this.model,
      ...this.validateForm.value,
      ...this.getEntity(),
    });
  }

  protected getEntity() {
    return {};
  }
}
